package com.db.controller;

import com.db.common.pojo.JsonResult;
import com.db.pojo.SysDept;
import com.db.service.SysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dept/")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @RequestMapping("doFindObjects")
    public JsonResult doFindObjects() {
        List<Map<String, Object>> list = sysDeptService.findObjects();
        return new JsonResult(list);
    }

    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id) {
        sysDeptService.deleteById(id);
        return new JsonResult("delete ok");
    }

    //doFindZTreeNodes
    @RequestMapping("doFindZTreeNodes")
    public JsonResult doFindZTreeNodes() {
        return new JsonResult(sysDeptService.findTree());
    }

    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(SysDept sysDept) {
        sysDeptService.insertObject(sysDept);
        return new JsonResult("save ok");
    }

    //doUpdateObject
    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(SysDept sysDept) {
        sysDeptService.updateObject(sysDept);
        return new JsonResult("update ok");
    }
}
